package work4.work1;

import java.io.*;

public class CopyTxt {
    public CopyTxt() {
        try {
            doWork();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    void doWork() throws IOException {
        //1.创建缓冲流的对象
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\javaprt\\javaprt\\schoolwork\\src\\work4\\a.txt"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\javaprt\\javaprt\\schoolwork\\src\\work4\\copy.txt"));
        //2.拷贝（一次读写多个字节）
        byte[] bytes = new byte[1024];
        int len;
        while((len = bis.read(bytes)) != -1){
            bos.write(bytes,0,len);
        }
        //3.释放资源
        bos.close();
        bis.close();
    }
}
